<template>
  <a-table
    :columns="columns"
    :data="tempOkrData"
    :pagination="false"
    :bordered="{ wrapper: true, cell: true }"
    :spanMethod="dataSpanMethod"
    :row-selection="showRowSelection ? {} : null"
    v-model:selectedKeys="selectedKeys"
    span-all
    stripe
    :row-key="'id'"
    @select="select"
  >
    <template #td="{ record, column }">
      <td
        :class="[
          column.dataIndex === 'index' && record.operate === 2
            ? 'add'
            : column.dataIndex === 'index' && record.operate === 3
            ? 'update'
            : (column.dataIndex === 'index' && record.operate === 4) ||
              (column.dataIndex === 'index' &&
                record.state === 2 &&
                templateData?.optionStatus === 4)
            ? 'del'
            : ''
        ]"
      />
    </template>
    <template #index="{ record }">
      {{ record.indexRow + 1 }}
    </template>
    <template #source="{ record }">
      {{ getIndexSourceName(record.source) }}
    </template>
    <template #type="{ record }">
      <template v-if="record.type">
        {{ record.type === 1 ? '定性指标' : '定量指标' }}
      </template>
    </template>
    <template #polarity="{ record }">
      <template v-if="record.polarity">
        {{ record.polarity === 1 ? '越大越好' : '越小越好' }}
      </template>
    </template>
    <template #referenceValue="{ record }">
      {{
        record.referenceValue
          ? `${record.referenceValue}${record.targetUnitValue}`
          : '--'
      }}
    </template>
    <template #targetValue="{ record }">
      {{
        record.targetValue
          ? `${record.targetValue}${record.targetUnitValue}`
          : '--'
      }}
    </template>
    <template #challengePoint="{ record }">
      {{
        record.challengePoint
          ? `${record.challengePoint}${record.targetUnitValue}`
          : '--'
      }}
    </template>
    <template #maxScore>
      {{ upperLimitScore ? upperLimitScore : '无限' }}
    </template>
    <template #indexWeight="{ record }">
      {{ record.indexWeight ? `${record.indexWeight}%` : '' }}
    </template>
    <template #inputValue="{ record }">
      <div v-if="props.args.showScoreInput && templateData?.optionStatus === 9">
        <a-input-number
          style="height: 100%"
          placeholder="录入值"
          hide-button
          v-model="tableData[record.indexRow].inputValue"
        />
      </div>
      <div v-else>{{ record.inputValue }}</div>
    </template>
    <!-- 自评 -->
    <template #owerScorerName="{ record }">
      {{ record.owerScorer?.userName }}
    </template>
    <template #owerScorerWeight="{ record }">
      {{
        record.owerScorer?.weight
          ? `${props.templateData?.selfEvaluation} %`
          : ''
      }}
      <!-- {{ record.owerScorer?.weight }} -->
    </template>
    <template #owerScorerMark="{ record }">
      <div
        v-if="
          props.args.showScoreInput &&
          record.owerScorer &&
          record.owerScorer.scoreIndex >= 0 &&
          (record.owerScorer.userId === userId ||
            record.owerScorer.isWaitDone === 1) &&
          templateData?.optionStatus === 8
        "
      >
        <a-input-number
          style="height: 100%"
          placeholder="评分"
          hide-button
          v-model="
            tableData[record.indexRow].scorer[record.owerScorer.scoreIndex]
              .score
          "
        />
      </div>
      <div v-else>{{ record.owerScorer?.score }}</div>
    </template>
    <template #owerScorerNote="{ record }">
      <div
        v-if="
          props.args.showScoreInput &&
          record.owerScorer &&
          record.owerScorer.scoreIndex >= 0 &&
          (record.owerScorer.userId === userId ||
            record.owerScorer.isWaitDone === 1) &&
          templateData?.optionStatus === 8
        "
      >
        <a-textarea
          style="height: 100%"
          auto-size
          placeholder="评分说明"
          allow-clear
          v-model="
            tableData[record.indexRow].scorer[record.owerScorer.scoreIndex].note
          "
        />
      </div>
      <div v-else>{{ record.owerScorer?.note }}</div>
    </template>
    <template #indexLibrary="{ record }">
      <!-- <div v-if="tableData[rowIndex].scorer">
        {{ getScorerName(tableData[rowIndex].scorer) }}
      </div> -->
      <a-space v-if="tableData[record.indexRow]?.scorer" wrap>
        <template
          v-for="user in tableData[record.indexRow].scorer"
          :key="user.id"
        >
          <a-tag
            v-if="user.type !== 5"
            color="arcoblue"
            :default-checked="true"
          >
            {{ user.userName }}({{ user.weight }}%)
          </a-tag>
        </template>
      </a-space>
      <div v-else>--</div>
    </template>
    <template #optional="{ record, rowIndex }">
      <a-tooltip content="编辑">
        <IconFont
          type="icon-edit"
          :size="26"
          :style="{
            marginRight: '10px',
            cursor: 'pointer'
          }"
          @click="goEdit(record, rowIndex)"
        />
      </a-tooltip>
      <a-tooltip content="设置评分人">
        <icon-user-add
          :size="24"
          style="color: #3c6eff"
          @click="setHuman(record, rowIndex)"
        />
      </a-tooltip>
      <a-tooltip content="删除" position="left">
        <a-popconfirm
          content="是否确认删除该条数据?"
          @ok="del(record.indexRow)"
        >
          <icon-font
            type="icon-delete"
            :size="26"
            :style="{
              cursor: 'pointer',
              marginRight: '10px'
            }"
          />
        </a-popconfirm>
      </a-tooltip>
    </template>
    <!-- 他评 -->

    <template #otherScorerName="{ record }">
      {{ record.otherScorer?.userName }}
      <template v-if="props.args.showWeight">
        {{
          record.otherScorer?.weight ? `(${record.otherScorer?.weight}%)` : ''
        }}
      </template>
    </template>
    <template #otherScorerWeight="{ record }">
      {{ record.otherScorer ? `100%` : '' }}
      <!-- {{
        record.scorerStatus?.other?.weight
          ? `${record.scorerStatus.other?.weight} %`
          : ''
      }} -->
    </template>
    <template #otherScorerMark="{ record }">
      <div
        v-if="
          props.args.showScoreInput &&
          record.otherScorer &&
          record.otherScorer.scoreIndex >= 0 &&
          (record.otherScorer.userId === userId ||
            record.otherScorer.isWaitDone === 1) &&
          templateData?.optionStatus === 9
        "
      >
        <a-input-number
          placeholder="评分"
          hide-button
          v-model="
            tableData[record.indexRow].scorer[record.otherScorer.scoreIndex]
              .score
          "
        />
      </div>
      <div v-else>{{ record.otherScorer?.score }}</div>
    </template>
    <template #otherScorerNote="{ record }">
      <div
        v-if="
          props.args.showScoreInput &&
          record.otherScorer &&
          record.otherScorer.scoreIndex >= 0 &&
          (record.otherScorer.userId === userId ||
            record.otherScorer.isWaitDone === 1) &&
          templateData?.optionStatus === 9
        "
      >
        <a-textarea
          style="height: 100%"
          auto-size
          placeholder="评分说明"
          allow-clear
          v-model="
            tableData[record.indexRow].scorer[record.otherScorer.scoreIndex]
              .note
          "
        />
      </div>
      <div v-else>{{ record.otherScorer?.note }}</div>
    </template>
    <template #returnReason="{ record }">
      <span v-if="props.args.showReason">
        {{ record.returnReason }}
      </span>
      <a-textarea
        v-else
        style="height: 100%"
        auto-size
        placeholder="退回原因"
        allow-clear
        v-model="tableData[record.tableIndex].returnReason"
      />
    </template>
    <template #scorer="{ record, rowIndex }">
      <a-tooltip content="编辑">
        <IconFont
          type="icon-edit"
          :size="26"
          :style="{
            cursor: 'pointer'
          }"
          @click="goEdit(record, rowIndex)"
        />
      </a-tooltip>
      <a-tooltip content="删除" position="left">
        <a-popconfirm
          content="是否确认删除该条数据?"
          @ok="del(record.indexRow)"
        >
          <icon-font
            type="icon-delete"
            :size="26"
            :style="{
              cursor: 'pointer',
              color: 'rgb(var(--red-6))'
            }"
          />
        </a-popconfirm>
      </a-tooltip>
    </template>
    <template #appeal="{ record }">
      <a-tooltip content="编辑">
        <IconFont
          type="icon-edit"
          :size="26"
          :style="{
            cursor: 'pointer'
          }"
          @click="appeal(record)"
        />
      </a-tooltip>
      <a-tooltip content="删除" position="left">
        <a-popconfirm content="是否确认删除该条数据?" @ok="remove(record)">
          <icon-font
            type="icon-delete"
            :size="26"
            :style="{
              cursor: 'pointer',
              marginRight: '10px',
              color: 'rgb(var(--red-6))'
            }"
          />
        </a-popconfirm>
      </a-tooltip>
    </template>
    <template #showAppealHandel="{ record }">
      <a-button type="text" @click="appealHandle(record)">申诉处理</a-button>
    </template>
    <template #showIsPass="{ record }">
      <a-button
        v-if="record.state === 5"
        @click="appealHandle(record)"
        type="outline"
        status="success"
      >
        <template #icon>
          <icon-check-circle />
        </template>
        通过
      </a-button>
      <a-button
        v-if="record.state === 6"
        @click="appealHandle(record)"
        type="outline"
        status="danger"
      >
        <template #icon>
          <icon-close-circle />
        </template>
        驳回
      </a-button>
      <span v-if="record.state < 5">--</span>
    </template>
    <template #indexScore="{ record }">
      {{ record.score }}
    </template>
  </a-table>
  <a-button v-if="props.args.showAdd" type="text" @click="add"
    >新增指标</a-button
  >
  <IndexDrawer
    v-model:visible="drawerVisible"
    @submit="submit"
    :data="currData"
  />
  <ScoreHumanModal
    v-model:visible="humanVisible"
    v-model:data="currHumanData"
    @save="saveHUman"
    @del="delHUman"
    :type="1"
    :indexType="3"
    v-model:del-ids="modelDeletedScorerIds"
  />
  <AppealDrawer
    v-model:visible="appealVisible"
    v-model:appealIndexData="appealIndexData"
    @save="saveAppeal"
  />
  <AppealDrawerHandle
    v-model:visible="appealDrawerHandleVisible"
    v-model:currentHandleData="currentHandleData"
    @save="saveAppeal"
    :display="templateData?.optionStatus === 16 ? true : false"
    :show-input-value="true"
  />
</template>

<script setup lang="ts">
import { cloneDeep } from 'lodash';
import { PerformanceKeyPerformanceIndexLibraryUse } from '@/apis/management/performance/baseSetting/template/type';
import IndexDrawer from './IndexDrawer.vue';
import WeightInfo from '../AbilityIndeTable/WeightInfo.vue';
import { PersonnelAbilityQualityIndexLibrary } from '@/apis/human/base/variationManager/probation/type';
import ScoreHumanModal from '../AbilityIndeTable/ScoreHumanModal.vue';
import { delExamineToolInfo } from '@/apis/human/base/variationManager/probation';
import { useVModel } from '@vueuse/core';
import { getIndexSourceName } from '@/utils/probation';
import { ProbationExamine } from '@/apis/human/base/variationManager/probation/type';
import AppealDrawer from '../conpenonts/AppealDrawer.vue';
import AppealDrawerHandle from '../conpenonts/AppealDrawerHandle.vue';
const props = withDefaults(
  defineProps<{
    review?: boolean;
    data: PerformanceKeyPerformanceIndexLibraryUse[];
    upperLimitScore?: number;
    showRowSelection?: boolean;
    templateData?: ProbationExamine;
    onlyShowSelected?: boolean;
    returnTemp: number; //只显示选中的数据

    selectedIds?: number[];
    deletedIds?: number[];
    deletedScorerIds?: number[];
    args?: {
      showAdd?: boolean; //显示新增
      showOperation?: boolean; //显示操作
      /**
       * 评分人显示样式。0集成，1区分不同评分人
       */
      scorerType?: number;
      /**
       * 是否显示分数输入框，默认false不开启，true开启
       */
      showScoreInput?: boolean;
      /**
       * 是否显示原因
       */
      showReason?: boolean;
      /**
       * 是否显示指标得分
       */
      showIndexScore?: boolean;
      /**
       * 是否显示申诉操作按钮
       */
      showAppeal?: boolean;
      /**
       * 是否显示申诉处理按钮
       */
      showAppealHandel?: boolean;
      /**
       * 是否显示审批通过与否
       */
      showIsPass?: boolean;
      /**
       * 是否多选框
       */
      showRowSelection?: boolean;
      /**
       * 是否显示权重
       */
      showWeight?: boolean;
    };
  }>(),
  {
    data: () => [],
    args: () => ({
      showAdd: true,
      showOperation: true,
      scorerType: 0,
      showScoreInput: false,
      showReason: false,
      showAppeal: false,
      showAppealHandel: false,
      showIndexScore: true,
      showIsPass: false,
      showRowSelection: false,
      showWeight: true
    }),
    selectedIds: () => [],
    deletedIds: () => [],
    deletedScorerIds: () => []
  }
);
const emit = defineEmits([
  'update:visible',
  'handleOk',
  'update:data',
  'update:selectedIds',
  'update:deletedIds',
  'update:deletedScorerIds'
]);
const tableData = useVModel(props, 'data', emit);
const selectedKeys = useVModel(props, 'selectedIds', emit);
const modelDeleted = useVModel(props, 'deletedIds', emit);
const modelDeletedScorerIds = useVModel(props, 'deletedScorerIds', emit);
const userId = Number(localStorage.getItem('userId'));
const handleOk = () => {
  emit('handleOk');
};
const change = () => {
  emit('update:data', tableData.value);
};

const columns = computed(() => {
  let colArr = [
    {
      title: '序号',
      dataIndex: 'index',
      slotName: 'index',
      width: 70,
      align: 'center'
    },
    {
      title: '指标来源',
      dataIndex: 'source',
      slotName: 'source',
      width: 150,
      align: 'center'
    },
    {
      title: '指标类型',
      dataIndex: 'type',
      slotName: 'type',
      width: 120,
      align: 'center'
    },
    {
      title: '指标名称',
      dataIndex: 'name',
      width: 150,
      align: 'center'
    },
    {
      title: '指标定义',
      dataIndex: 'indexDefinition',
      width: 200,
      align: 'center'
    },
    {
      title: '项目界定',
      dataIndex: 'projectDefinition',
      width: 200,
      align: 'center'
    },
    {
      title: '指标极性',
      dataIndex: 'polarity',
      slotName: 'polarity',
      width: 120,
      align: 'center'
    },
    {
      title: '指标公式/说明',
      dataIndex: 'instructions',
      width: 200,
      align: 'center'
    },
    {
      title: '评分标准/规则',
      dataIndex: 'rule',
      width: 200,
      align: 'center'
    },
    {
      title: '考核目标',
      dataIndex: 'referenceValue',
      align: 'center',
      children: [
        {
          title: '考核基准值',
          dataIndex: 'referenceValue',
          slotName: 'referenceValue',
          width: 120,
          align: 'center'
        },
        {
          title: '考核目标值',
          dataIndex: 'targetValue',
          slotName: 'targetValue',
          width: 120,
          align: 'center'
        },
        {
          title: '考核挑战值',
          dataIndex: 'challengePoint',
          slotName: 'challengePoint',
          width: 120,
          align: 'center'
        }
      ]
    }
  ];

  if (props.args.showWeight) {
    const indexWeight = {
      title: '指标权重',
      dataIndex: 'indexWeight',
      slotName: 'indexWeight',
      width: 100,
      align: 'center'
    };
    colArr.push(indexWeight);
  }
  if (
    props.templateData.optionStatus >= 7 &&
    props.templateData.optionStatus !== 8
  ) {
    const inputValue = {
      title: '录入值',
      dataIndex: 'inputValue',
      slotName: 'inputValue',
      width: 100,
      align: 'center'
    };
    colArr.push(inputValue);
  }
  if (!props.args.scorerType) {
    const maxScore = {
      title: '评分上限',
      dataIndex: 'maxScore',
      slotName: 'maxScore',
      width: 100,
      align: 'center'
    };
    const indexLibrary = {
      title: '评分人',
      dataIndex: 'indexLibrary',
      slotName: 'indexLibrary',
      width: 400,
      align: 'center'
    };
    colArr.splice(3, 0, maxScore);
    colArr.push(indexLibrary);
  } else {
    const owerScorer = {
      title: '员工自评',
      dataIndex: 'owerScorer',
      slotName: 'owerScorer',
      width: 200,
      align: 'center',
      children: [
        {
          title: '评分人',
          dataIndex: 'owerScorerName',
          slotName: 'owerScorerName',
          width: 100,
          align: 'center'
        },

        {
          title: '评分',
          dataIndex: 'owerScorerMark',
          slotName: 'owerScorerMark',
          width: 100,
          align: 'center'
        },
        {
          title: '评分说明',
          dataIndex: 'owerScorerNote',
          slotName: 'owerScorerNote',
          width: 300,
          align: 'center'
        }
      ]
    };
    if (props.args.showWeight) {
      const scorerWeight = {
        title: '权重',
        dataIndex: 'owerScorerWeight',
        slotName: 'owerScorerWeight',
        width: 100,
        align: 'center'
      };
      owerScorer.children.splice(1, 0, scorerWeight);
    }
    colArr.push(owerScorer);
    const otherScorer = {
      title: '考核评分',
      dataIndex: 'otherScorer',
      slotName: 'otherScorer',
      width: 200,
      align: 'center',
      children: [
        {
          title: '评分人',
          dataIndex: 'otherScorerName',
          slotName: 'otherScorerName',
          width: 100,
          align: 'center'
        },

        {
          title: '评分',
          dataIndex: 'otherScorerMark',
          slotName: 'otherScorerMark',
          width: 100,
          align: 'center'
        },
        {
          title: '评分说明',
          dataIndex: 'otherScorerNote',
          slotName: 'otherScorerNote',
          width: 300,
          align: 'center'
        }
      ]
    };
    if (props.args.showWeight) {
      const scorerWeight = {
        title: '评分人总权重',
        dataIndex: 'otherScorerWeight',
        slotName: 'otherScorerWeight',
        width: 130,
        align: 'center'
      };
      otherScorer.children.splice(1, 0, scorerWeight);
    }
    colArr.push(otherScorer);
  }
  if (props.args.showIndexScore) {
    const indexScore = {
      title: '指标得分',
      dataIndex: 'indexScore',
      slotName: 'indexScore',
      width: 100,
      align: 'center'
    };
    colArr.push(indexScore);
  }
  const appeal = {
    title: '操作',
    dataIndex: 'appeal',
    slotName: 'appeal',
    width: 120,
    align: 'center',
    fixed: 'right'
  };
  if (props.args.showAppeal) colArr.push(appeal);
  const showAppealHandel = {
    title: '操作',
    dataIndex: 'showAppealHandel',
    slotName: 'showAppealHandel',
    width: 100,
    align: 'center',
    fixed: 'right'
  };
  if (props.args.showAppealHandel) colArr.push(showAppealHandel);
  const showIsPass = {
    title: '操作',
    dataIndex: 'showIsPass',
    slotName: 'showIsPass',
    width: 100,
    align: 'center',
    fixed: 'right'
  };
  if (props.args.showIsPass) colArr.push(showIsPass);
  if (props.returnTemp === 2 || props.args.showReason) {
    const returnReason = {
      title: '退回原因',
      dataIndex: 'returnReason',
      slotName: 'returnReason',
      fixed: 'right',
      width: 200,
      align: 'center'
    };
    colArr.push(returnReason);
  } else {
    const index = colArr.findIndex((item) => item.title === '退回原因');
    if (index >= 0) {
      colArr.splice(index, 1);
    }
  }
  if (props.args.showOperation) {
    const optional = {
      title: '操作',
      dataIndex: 'optional',
      slotName: 'optional',
      width: 150,
      align: 'center',
      fixed: 'right'
    };
    colArr.push(optional);
  }
  return colArr;
});

const currData = ref<PerformanceKeyPerformanceIndexLibraryUse>({});
const drawerVisible = ref(false);
const editIndex = ref(-1); //编辑项的下标，用以判断新增和编辑，下标小于0是新增数据。大于等于0则是修改此下标的值
const add = () => {
  editIndex.value = -1;
  currentIndex.value = -1;
  currData.value = {
    indexWeight: 0,
    status: 1,
    name: ''
  };
  drawerVisible.value = true;
};

const goEdit = (
  data: PerformanceKeyPerformanceIndexLibraryUse,
  index: number
) => {
  editIndex.value = index;
  currData.value = data;
  drawerVisible.value = true;
};
const submit = (data: PerformanceKeyPerformanceIndexLibraryUse) => {
  //判断是新增还是编辑
  if (editIndex.value < 0) {
    //新增
    tableData.value?.push(data);
    add();
  } else {
    //编辑
    if (!tableData.value?.length) return;

    tableData.value[editIndex.value] = data;
  }
};
const showTitle = reactive({
  appoit: false,
  junior: false,
  other: false,
  peer: false,
  superiors: false
});
//表格显示的数据
const tempOkrData: any = computed(() => {
  let newArr: any = [];
  if (Array.isArray(tableData.value) && tableData.value?.length > 0) {
    let i = 1;
    tableData.value.forEach((item, index: number) => {
      if (
        props.onlyShowSelected &&
        !selectedKeys.value.includes(item.id) &&
        [3, 21].includes(props.templateData?.optionStatus)
      ) {
        return;
      }
      if (index > 0 && tableData.value[index - 1]?.name === item?.name) {
        if (item) {
          item.index = tableData.value[index - 1]?.index;
        }
      } else {
        item.index = i;
        i++;
      }
      if (item?.scorer?.length) {
        const owerScorer: any[] = [];
        const otherScorer: any[] = [];
        item.scorer.forEach((scorer, scoreIndex: any) => {
          if (scorer.type && scorer.type > 0) {
            scorer.scoreIndex = scoreIndex;
            if (scorer.type === 5) {
              owerScorer.push(scorer);
            } else {
              otherScorer.push(scorer);
              showTitle.other = true;
            }
          }
        });
        //获取最大值，得出需要合并多少格
        const maxLength = Math.max(owerScorer.length, otherScorer.length);
        for (let n = 0; n < maxLength; n++) {
          const scorerArr = {
            owerScorer: owerScorer[n],
            otherScorer: otherScorer[n]
          };
          const resultRowspan = n === 0 ? maxLength : 0;
          newArr.push({
            ...item,
            ...scorerArr,
            resultRowspan,
            indexRow: index,
            tableIndex: index
          });
        }
      } else {
        newArr.push({
          ...item,
          indexRow: index,
          tableIndex: index
        });
      }
    });
    // console.log('newArr', newArr);

    return newArr;
  } else return [];
});
// 表格合并
const dataSpanMethod = (datas: any) => {
  const { record, rowIndex, columnIndex, column } = datas;
  // 处理rowSpan
  const obj = {
    rowspan: 2,
    colspan: 1
  };
  const enums = ['achievementName', 'achievementWeight', 'indexScore'];
  const enums2 = [
    'achievementName',
    'achievementWeight',
    'optional',
    'appointScorerWeight',
    'otherScorerWeight',
    'peerScorerWeight',
    'juniorScorerWeight',
    'superiorsScorerWeight',
    'owerScorerName',
    'owerScorerWeight',
    'owerScorerMark',
    'owerScorerNote'
  ];
  if (props.args.scorerType) {
    if (record.resultRowspan && enums2.includes(column.dataIndex)) {
      return {
        rowspan: record.resultRowspan
        // colspan: 1
      };
    }
    if (
      columnIndex === 0 &&
      tempOkrData.value[rowIndex - 1]?.indexRow !== record?.indexRow
    ) {
      let arr = tempOkrData.value.filter(
        (item: any) => item?.indexRow === record?.indexRow
      );

      obj.rowspan = arr?.length;
      return obj;
    }
    if (
      [
        'name',
        'index',
        'returnReason',
        'scorer',
        'indexScore',
        'weight',
        'appeal',
        'showAppealHandel',
        'showIsPass',
        'indexDefinition',
        'auditOpinion',
        'instructions',
        'type',
        'returnReason',
        'source',
        'rule',
        'polarity',
        'projectDefinition',
        'targetValue',
        'referenceValue',
        'isUseReferenceValue',
        'isUserChallengePoint',
        'challengePoint',
        'otherScorerWeight',
        'optional',
        'indexLibrary',
        'inputValue',
        'indexWeight'
      ].includes(column.dataIndex) &&
      tempOkrData.value[rowIndex - 1]?.indexRow !== record?.indexRow
    ) {
      let arr = tempOkrData.value.filter(
        (item: any) => item?.indexRow === record?.indexRow
      );
      obj.rowspan = arr?.length;
    } else {
      obj.rowspan = 0;
    }
  } else {
    let arr = tempOkrData.value.filter(
      (item: any) => item?.indexRow === record?.indexRow
    );
    if (
      !enums.includes(column.dataIndex) &&
      tempOkrData.value[rowIndex - 1]?.indexRow !== record?.indexRow
    ) {
      obj.rowspan = arr?.length;
    } else {
      obj.rowspan = 0;
    }
  }

  return obj;
};
const humanVisible = ref(false);
const currHumanData = ref<PersonnelAbilityQualityIndexLibrary>();
const currentIndex = ref(0);
const setHuman = (data: PersonnelAbilityQualityIndexLibrary, index: number) => {
  data.scorer = data.scorer ? data.scorer : [];
  data.scorerStatus = data.scorerStatus || {
    appoint: { status: 2, weight: 0 },
    superiors: { status: 2, weight: 0 },
    junior: { status: 2, weight: 0 },
    peer: { status: 2, weight: 0 },
    other: { status: 2, weight: 0 }
  };

  // console.log('data', data);
  humanVisible.value = true;
  currentIndex.value = data.indexRow;
  currHumanData.value = cloneDeep(data);
};
const saveHUman = () => {
  if (!tableData.value?.length) return;
  tableData.value[currentIndex.value] = currHumanData.value;
  humanVisible.value = false;
};
const delHUman = () => {
  if (!tableData.value?.length) return;
  tableData.value[currentIndex.value] = currHumanData.value;
  console.log('modelDeleted.value', modelDeleted.value);
};
const del = async (index: number) => {
  if (!tableData.value?.length) return;
  const { id } = tableData.value[index];
  if (id > 0) {
    modelDeleted.value.push(id);
    // await delExamineToolInfo({ ids: [id], type: 3 });
  }
  tableData.value.splice(index, 1);
  // change();
};
const getScorerName = (arr: any[]) => {
  if (!Array.isArray(arr) || !arr.length) return '--';
  let newArr: any[] = [];
  arr.forEach((user) => {
    if (user.type === 5) return;
    newArr.push(user.userName);
  });
  return newArr.join(',') || '--';
};
const select = (rowKeys: any, rowKey: any, record: any) => {
  if (selectedKeys.value?.includes(record.id)) {
    selectedKeys.value = selectedKeys.value.filter(
      (item) => item !== record.id
    );
  } else {
    selectedKeys.value?.push(record.id);
  }
  record.isReturn = !record.isReturn;
  const index = tableData.value.findIndex((item) => item.id === rowKey);
  if (index >= 0) {
    tableData.value[index].isReturn = !tableData.value[index].isReturn;
  }
  console.log('rowKeys', tableData.value);
  // console.log('rowKey', rowKey);
  // console.log('record', record);
};
const appealIndexData = ref<any>();
const appealVisible = ref(false);
const editTargetIndex = ref(0);
const appeal = async (data: any) => {
  editTargetIndex.value = data.indexRow;
  appealVisible.value = true;
  appealIndexData.value = data;
};
const saveAppeal = (data: any) => {
  tableData.value[editTargetIndex.value] = data;
};
const remove = (data: any) => {
  const index = selectedKeys.value?.findIndex((key) => key === data.id);
  if (index < 0) return;
  selectedKeys.value.splice(index, 1);
  tableData.value.splice(data.indexRow, 1);
};
const appealDrawerHandleVisible = ref(false);
const appealHandleIndex = ref();
const currentHandleData = ref<any>();
const appealHandle = (data: any) => {
  currentHandleData.value = data;
  appealHandleIndex.value = data.indexRow;
  appealDrawerHandleVisible.value = true;
};
</script>

<style lang="less" scoped>
.add {
  border-left: 2px solid #00b42a;
}
.update {
  border-left: 2px solid #165dff;
}
.del {
  border-left: 2px solid #f53f3f;
}
</style>
